<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1.5em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css"/>
<link rel="stylesheet" type="text/css" href="/css/validator.css"/>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script language="javascript">
$().ready( function(){

	$('#startDate').datepick({minDate: new Date(<%=request.getAttribute("eminDate").toString()%>), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
	$('#endDate').datepick({minDate: new Date(<%=request.getAttribute("eminDate").toString()%>),showOn: 'both',beforeShow:customRange,numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"});
	function customRange (){
		var startDt = $('#startDate').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt}; 
	}

	if('${id}'==''){
		$("h1").eq(0).text('新增');
	}

	if('${mgType}'=='1'){
		if($('#prodId').val().length!=0){
			getProductInfo2("${midContextPath}","prod_data",$('#prodId').val());
		}
	}

	$('#prodId').numeric();
	$('#prodId').blur(function(){
		$(this).val(prodPadLeft($(this).val()));
		getProductInfo2("${midContextPath}","prod_data",$('#prodId').val());
	});

	$('#radio_1').click(function(){
		$('#gift').show();
		$('#redirect').hide();
	});

	$('#radio_3').click(function(){
		$('#gift').hide();
		$('#redirect').show();
	});

	$('#submit_button').click(function(){
		var isCorrect = true;
		$("span:[class=msg rn]").hide();
		if($('#startDate').val()==''){
			$('#startDateTip').text('请输入起始日期');
			$('#startDateTip').show();
			isCorrect = false;
		}
		if($('#startTime').val()==''){
			$('#startTimeTip').text('请输入起始时间');
			$('#startTimeTip').show();
			isCorrect = false;
		}
		if($('#endDate').val()==''){
			$('#endDateTip').text('请输入结束日期');
			$('#endDateTip').show();
			isCorrect = false;
		}
		if($('#endTime').val()==''){
			$('#endTimeTip').text('请输入结束时间');
			$('#endTimeTip').show();
			isCorrect = false;
		}
		if($('#startDate').val()>$('#endDate').val()){
			$('#endDateTip').text('结束日期不能小于起始日期');
			$('#endDateTip').show();
			isCorrect = false;
		}else if($('#startDate').val()==$('#endDate').val()){
			if($('#startTime').val()>=$('#endTime').val()){
				$('#endTimeTip').text('结束时间需大于起始时间');
				$('#endTimeTip').show();
				isCorrect = false;
			}
		}

		if($('#name').val()==''){
			$('#nameTip').text('请输入活动名称');
			$('#nameTip').show();
			isCorrect = false;
		}
		
		if($('#radio_1').attr('checked')==true){
			if( $('#prodId').val()==''){
				$('#prodTip').text('请输入商品编号');
				$('#prodTip').show();
				isCorrect = false;
			}else if( $('#prod_data').val()=='查无此商品' || $('#coupon_data').val()=='此商品已被删除'|| $('#coupon_data').val()=='商品状态不正确'){
				$('#prodTip').text('请输入正确商品编号');
				$('#prodTip').show();
				isCorrect = false;
			}
		}else if($('#radio_3').attr('checked')==true){
			if ( $("#redirect_url").val() =='' ){
				$("#urlTip").text("请输入连结");
				$("#urlTip").show();
				isCorrect = false;
			}else if ( !isURL($("#redirect_url").val()) ){
				$("#urlTip").text("连结格式错误");
				$("#urlTip").show();
				isCorrect = false;
			}
		}
		
		if($('#memo').val()==''){
			$('#memoTip').text('请输入活动说明');
			$('#memoTip').show();
			isCorrect = false;
		}
		if(isCorrect){
			$('#mgForm').submit();
		}
	});
});
</script>
<s:actionerror/>
<s:actionmessage/>
<s:fielderror/>
<br/>
<h1>编辑<br/>
<div class="f-link"><a href="${midContextPath}/membergift/search.do">回列表</a></div>
</h1>

<s:form action="save.do" method="post" id="mgForm">
	<table class="tb-data" width="100%">
		<tr>
			<th>#</th>
			<td>${id}<input type="hidden" name="annId" value="${id}"></td>
		</tr>
		<tr>
			<th>渠道名称</th>
			<td>
				<s:select id="asname" name="asname" list="channelNameMenu.options" listKey="key" listValue="value.name" value="%{asname}"/>
			</td>
		</tr>
		<tr>
			<th>起始日期</th>
			<td>
				<input name="startDate" type="text" id="startDate" value="${startDate}" size="10" maxlength="10">
				<select id="startTime" name="startTime">			
					<c-rt:forEach begin="0" end="23" var="t1">
						<c-rt:if test="${t1<10}">
						<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t1>=10}">
						<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
					</c-rt:forEach>
				</select><br/>
				<span id="startDateTip" class="msg rn" style="display:none;"></span><span id="startTimeTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>结束日期</th>
			<td>
				<input name="endDate" type="text" id="endDate"
				value="${endDate}" size="10" maxlength="10">
				<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select><br/>
				<span id="endDateTip" class="msg rn" style="display:none;"></span><span id="endTimeTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>活动名称</th>
			<td>
				<input type="text" id="name" name="name" value="${name}" maxlength="100" size="50"/><br/>
				<span id="nameTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>活动内容</th>
			<td>
				<input type="radio" name="mgType" value="1" id="radio_1" <c-rt:if test="${mgType eq '1'}">checked="checked"</c-rt:if>/>赠品 
				<input type="radio" name="mgType" value="3" id="radio_3" <c-rt:if test="${mgType eq '3'}">checked="checked"</c-rt:if>/>转址<br/>
			</td>
		</tr>
		<tr id="gift" <c-rt:if test="${mgType ne '1'}">style="display:none;"</c-rt:if>>
			<th>商品编号</th>
			<td>
				<input id="prodId" type="text" name="prodId" value="${prodId}" maxlength="10" size="10"/> <input type="text" id="prod_data" size="50" disabled/>
				<br/><span id="prodTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr id="redirect" <c-rt:if test="${mgType ne '3'}">style="display:none;"</c-rt:if>>
			<th>转址连结</th>
			<td>
				<input id="redirect_url" type="text" name="redirect_url" value="${redirect_url}" maxlength="100" size="50"/>
				<br/><span id="urlTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>活动说明</th>
			<td>
				<input type="text" id="memo" name="memo" value="${memo}" maxlength="100" size="100"/><br/>
				<span id="memoTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
	</table>
	<br/>
	<input type="button" id="submit_button" value="送出"/>
	<input type="button" onclick="window.location='search.do'" value="Cancel"/>
</s:form>